package com.sangananitsolution.database;

import java.util.ArrayList;

import com.sangananitsolution.database.DatabaseTables.FavouitreItem;
import com.sangananitsolution.database.DatabaseTables.UserInfo;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class FavouirteItemCRUD {

	static DatabaseHelper databaseHelper = null;
	Context contextvalue;

	public FavouirteItemCRUD(Context context) {
		

		databaseHelper = new DatabaseHelper(context);
		contextvalue = context;
	}

	public void insertAllData(String imagesmain, String garageSaleTitlemain,
			String startdatemain, String oneOrTwoDaySalemain,
			String startimemain, String finishtimemain, String unitStreeNomain,
			String streeNamemain, String suburb, String citymain,
			String statemain, String postCodearraymain, String dsecription,
			String earlyBirdMessagemain, String badWeatherMessagemain,
			String goodsTypearraymain, String currentUsermain,
			String longitudemain, String latitudemain, String productIDmain) {

		// Fetching the sqLiteDatabase in the writeable mode

		if (databaseHelper != null) {
			SQLiteDatabase sqLiteDatabase = databaseHelper
					.getWritableDatabase();
			ContentValues content = new ContentValues();
			content.put(FavouitreItem.ProductImages, imagesmain);
			content.put(FavouitreItem.GarageSaleTitle, garageSaleTitlemain);
			content.put(FavouitreItem.StartDate, startdatemain);
			content.put(FavouitreItem.OneOrTwoDaySale, oneOrTwoDaySalemain);
			content.put(FavouitreItem.SaleStartTime, startimemain);
			content.put(FavouitreItem.SaleFinishTime, finishtimemain);
			content.put(FavouitreItem.UnitStreeNo, unitStreeNomain);
			content.put(FavouitreItem.StreeName, streeNamemain);
			content.put(FavouitreItem.Suburb, suburb);
			content.put(FavouitreItem.City, citymain);
			content.put(FavouitreItem.State, statemain);
			content.put(FavouitreItem.PostCode, postCodearraymain);
			content.put(FavouitreItem.Description, dsecription);
			content.put(FavouitreItem.EarlyBirdMessage, earlyBirdMessagemain);
			content.put(FavouitreItem.BadWeatherMessage, badWeatherMessagemain);
			content.put(FavouitreItem.GoodsType, goodsTypearraymain);
			content.put(FavouitreItem.CurrentUser, currentUsermain);
			content.put(FavouitreItem.Longitude, longitudemain);
			content.put(FavouitreItem.Latitude, latitudemain);
			content.put(FavouitreItem.ProductID, productIDmain);
			sqLiteDatabase.insert(FavouitreItem.TABLE_NAME, null, content);

		}

	}

	public ArrayList<String> getProductImage() {
		// Fetching the sqLiteDatabase in the readable mode

		ArrayList<String> badwheaterarrayList = new ArrayList<String>();
		if (databaseHelper != null) {

			SQLiteDatabase sqLiteDatabase = databaseHelper
					.getReadableDatabase();
			String[] column = { FavouitreItem.ProductImages};
			Cursor cursor = sqLiteDatabase.query(FavouitreItem.TABLE_NAME, column,null,null,null,null,null);
			
			if (cursor.moveToFirst())

				do {
					badwheaterarrayList.add(cursor.getString(cursor
							.getColumnIndex(FavouitreItem.ProductImages)));	 
				} while (cursor.moveToNext());
		}
		
		return badwheaterarrayList;
	}

	public ArrayList<String> getGarageSaleTitle() {
		// Fetching the sqLiteDatabase in the readable mode

		ArrayList<String> badwheaterarrayList = new ArrayList<String>();
		if (databaseHelper != null) {

			SQLiteDatabase sqLiteDatabase = databaseHelper
					.getReadableDatabase();
			String[] column = { FavouitreItem.GarageSaleTitle};
			Cursor cursor = sqLiteDatabase.query(FavouitreItem.TABLE_NAME, column,null,null,null,null,null);
			
			if (cursor.moveToFirst())

				do {
					badwheaterarrayList.add(cursor.getString(cursor
							.getColumnIndex(FavouitreItem.GarageSaleTitle)));	 
				} while (cursor.moveToNext());
		}
		
		return badwheaterarrayList;
	}
	public ArrayList<String> getStartDate() {
		// Fetching the sqLiteDatabase in the readable mode

		ArrayList<String> badwheaterarrayList = new ArrayList<String>();
		if (databaseHelper != null) {

			SQLiteDatabase sqLiteDatabase = databaseHelper
					.getReadableDatabase();
			String[] column = { FavouitreItem.StartDate};
			Cursor cursor = sqLiteDatabase.query(FavouitreItem.TABLE_NAME, column,null,null,null,null,null);
			
			if (cursor.moveToFirst())

				do {
					badwheaterarrayList.add(cursor.getString(cursor
							.getColumnIndex(FavouitreItem.StartDate)));	 
				} while (cursor.moveToNext());
		}
		
		return badwheaterarrayList;
	}
	public ArrayList<String> getOneOrTwoDaySale() {
		// Fetching the sqLiteDatabase in the readable mode

		ArrayList<String> badwheaterarrayList = new ArrayList<String>();
		if (databaseHelper != null) {

			SQLiteDatabase sqLiteDatabase = databaseHelper
					.getReadableDatabase();
			String[] column = { FavouitreItem.OneOrTwoDaySale};
			Cursor cursor = sqLiteDatabase.query(FavouitreItem.TABLE_NAME, column,null,null,null,null,null);
			
			if (cursor.moveToFirst())

				do {
					badwheaterarrayList.add(cursor.getString(cursor
							.getColumnIndex(FavouitreItem.OneOrTwoDaySale)));	 
				} while (cursor.moveToNext());
		}
		
		return badwheaterarrayList;
	}
	public ArrayList<String> getSaleStartTime() {
		// Fetching the sqLiteDatabase in the readable mode

		ArrayList<String> badwheaterarrayList = new ArrayList<String>();
		if (databaseHelper != null) {

			SQLiteDatabase sqLiteDatabase = databaseHelper
					.getReadableDatabase();
			String[] column = { FavouitreItem.SaleStartTime};
			Cursor cursor = sqLiteDatabase.query(FavouitreItem.TABLE_NAME, column,null,null,null,null,null);
			
			if (cursor.moveToFirst())

				do {
					badwheaterarrayList.add(cursor.getString(cursor
							.getColumnIndex(FavouitreItem.SaleStartTime)));	 
				} while (cursor.moveToNext());
		}
		
		return badwheaterarrayList;
	}
	public ArrayList<String> getSaleFinishTime() {
		// Fetching the sqLiteDatabase in the readable mode

		ArrayList<String> badwheaterarrayList = new ArrayList<String>();
		if (databaseHelper != null) {

			SQLiteDatabase sqLiteDatabase = databaseHelper
					.getReadableDatabase();
			String[] column = { FavouitreItem.SaleFinishTime};
			Cursor cursor = sqLiteDatabase.query(FavouitreItem.TABLE_NAME, column,null,null,null,null,null);
			
			if (cursor.moveToFirst())

				do {
					badwheaterarrayList.add(cursor.getString(cursor
							.getColumnIndex(FavouitreItem.SaleFinishTime)));	 
				} while (cursor.moveToNext());
		}
		
		return badwheaterarrayList;
	}
	public ArrayList<String> getUnitStreeNo() {
		// Fetching the sqLiteDatabase in the readable mode

		ArrayList<String> badwheaterarrayList = new ArrayList<String>();
		if (databaseHelper != null) {

			SQLiteDatabase sqLiteDatabase = databaseHelper
					.getReadableDatabase();
			String[] column = { FavouitreItem.UnitStreeNo};
			Cursor cursor = sqLiteDatabase.query(FavouitreItem.TABLE_NAME, column,null,null,null,null,null);
			
			if (cursor.moveToFirst())

				do {
					badwheaterarrayList.add(cursor.getString(cursor
							.getColumnIndex(FavouitreItem.UnitStreeNo)));	 
				} while (cursor.moveToNext());
		}
		
		return badwheaterarrayList;
	}
	public ArrayList<String> getStreeName() {
		// Fetching the sqLiteDatabase in the readable mode

		ArrayList<String> badwheaterarrayList = new ArrayList<String>();
		if (databaseHelper != null) {

			SQLiteDatabase sqLiteDatabase = databaseHelper
					.getReadableDatabase();
			String[] column = { FavouitreItem.StreeName};
			Cursor cursor = sqLiteDatabase.query(FavouitreItem.TABLE_NAME, column,null,null,null,null,null);
			
			if (cursor.moveToFirst())

				do {
					badwheaterarrayList.add(cursor.getString(cursor
							.getColumnIndex(FavouitreItem.StreeName)));	 
				} while (cursor.moveToNext());
		}
		
		return badwheaterarrayList;
	}
	public ArrayList<String> getSuburb() {
		// Fetching the sqLiteDatabase in the readable mode

		ArrayList<String> badwheaterarrayList = new ArrayList<String>();
		if (databaseHelper != null) {

			SQLiteDatabase sqLiteDatabase = databaseHelper
					.getReadableDatabase();
			String[] column = { FavouitreItem.Suburb};
			Cursor cursor = sqLiteDatabase.query(FavouitreItem.TABLE_NAME, column,null,null,null,null,null);
			
			if (cursor.moveToFirst())

				do {
					badwheaterarrayList.add(cursor.getString(cursor
							.getColumnIndex(FavouitreItem.Suburb)));	 
				} while (cursor.moveToNext());
		}
		
		return badwheaterarrayList;
	}
	public ArrayList<String> getCity() {
		// Fetching the sqLiteDatabase in the readable mode

		ArrayList<String> badwheaterarrayList = new ArrayList<String>();
		if (databaseHelper != null) {

			SQLiteDatabase sqLiteDatabase = databaseHelper
					.getReadableDatabase();
			String[] column = { FavouitreItem.City};
			Cursor cursor = sqLiteDatabase.query(FavouitreItem.TABLE_NAME, column,null,null,null,null,null);
			
			if (cursor.moveToFirst())

				do {
					badwheaterarrayList.add(cursor.getString(cursor
							.getColumnIndex(FavouitreItem.City)));	 
				} while (cursor.moveToNext());
		}
		
		return badwheaterarrayList;
	}
	public ArrayList<String> getState() {
		// Fetching the sqLiteDatabase in the readable mode

		ArrayList<String> badwheaterarrayList = new ArrayList<String>();
		if (databaseHelper != null) {

			SQLiteDatabase sqLiteDatabase = databaseHelper
					.getReadableDatabase();
			String[] column = { FavouitreItem.State};
			Cursor cursor = sqLiteDatabase.query(FavouitreItem.TABLE_NAME, column,null,null,null,null,null);
			
			if (cursor.moveToFirst())

				do {
					badwheaterarrayList.add(cursor.getString(cursor
							.getColumnIndex(FavouitreItem.State)));	 
				} while (cursor.moveToNext());
		}
		
		return badwheaterarrayList;
	}
	public ArrayList<String> getPostCode() {
		// Fetching the sqLiteDatabase in the readable mode

		ArrayList<String> badwheaterarrayList = new ArrayList<String>();
		if (databaseHelper != null) {

			SQLiteDatabase sqLiteDatabase = databaseHelper
					.getReadableDatabase();
			String[] column = { FavouitreItem.PostCode};
			Cursor cursor = sqLiteDatabase.query(FavouitreItem.TABLE_NAME, column,null,null,null,null,null);
			
			if (cursor.moveToFirst())

				do {
					badwheaterarrayList.add(cursor.getString(cursor
							.getColumnIndex(FavouitreItem.PostCode)));	 
				} while (cursor.moveToNext());
		}
		
		return badwheaterarrayList;
	}
	public ArrayList<String> getDescription() {
		// Fetching the sqLiteDatabase in the readable mode

		ArrayList<String> badwheaterarrayList = new ArrayList<String>();
		if (databaseHelper != null) {

			SQLiteDatabase sqLiteDatabase = databaseHelper
					.getReadableDatabase();
			String[] column = { FavouitreItem.Description};
			Cursor cursor = sqLiteDatabase.query(FavouitreItem.TABLE_NAME, column,null,null,null,null,null);
			
			if (cursor.moveToFirst())

				do {
					badwheaterarrayList.add(cursor.getString(cursor
							.getColumnIndex(FavouitreItem.Description)));	 
				} while (cursor.moveToNext());
		}
		
		return badwheaterarrayList;
	}
	public ArrayList<String> getEarlyBirdMessage() {
		// Fetching the sqLiteDatabase in the readable mode

		ArrayList<String> badwheaterarrayList = new ArrayList<String>();
		if (databaseHelper != null) {

			SQLiteDatabase sqLiteDatabase = databaseHelper
					.getReadableDatabase();
			String[] column = { FavouitreItem.EarlyBirdMessage};
			Cursor cursor = sqLiteDatabase.query(FavouitreItem.TABLE_NAME, column,null,null,null,null,null);
			
			if (cursor.moveToFirst())

				do {
					badwheaterarrayList.add(cursor.getString(cursor
							.getColumnIndex(FavouitreItem.EarlyBirdMessage)));	 
				} while (cursor.moveToNext());
		}
		
		return badwheaterarrayList;
	}
	public ArrayList<String> getGoodsType() {
		// Fetching the sqLiteDatabase in the readable mode

		ArrayList<String> badwheaterarrayList = new ArrayList<String>();
		if (databaseHelper != null) {

			SQLiteDatabase sqLiteDatabase = databaseHelper
					.getReadableDatabase();
			String[] column = { FavouitreItem.GoodsType};
			Cursor cursor = sqLiteDatabase.query(FavouitreItem.TABLE_NAME, column,null,null,null,null,null);
			
			if (cursor.moveToFirst())

				do {
					badwheaterarrayList.add(cursor.getString(cursor
							.getColumnIndex(FavouitreItem.GoodsType)));	 
				} while (cursor.moveToNext());
		}
		
		return badwheaterarrayList;
	}
	public ArrayList<String> getCurrentUser() {
		// Fetching the sqLiteDatabase in the readable mode

		ArrayList<String> badwheaterarrayList = new ArrayList<String>();
		if (databaseHelper != null) {

			SQLiteDatabase sqLiteDatabase = databaseHelper
					.getReadableDatabase();
			String[] column = { FavouitreItem.CurrentUser};
			Cursor cursor = sqLiteDatabase.query(FavouitreItem.TABLE_NAME, column,null,null,null,null,null);
			
			if (cursor.moveToFirst())

				do {
					badwheaterarrayList.add(cursor.getString(cursor
							.getColumnIndex(FavouitreItem.CurrentUser)));	 
				} while (cursor.moveToNext());
		}
		
		return badwheaterarrayList;
	}
	public ArrayList<String> getLongitude() {
		// Fetching the sqLiteDatabase in the readable mode

		ArrayList<String> badwheaterarrayList = new ArrayList<String>();
		if (databaseHelper != null) {

			SQLiteDatabase sqLiteDatabase = databaseHelper
					.getReadableDatabase();
			String[] column = { FavouitreItem.Longitude};
			Cursor cursor = sqLiteDatabase.query(FavouitreItem.TABLE_NAME, column,null,null,null,null,null);
			
			if (cursor.moveToFirst())

				do {
					badwheaterarrayList.add(cursor.getString(cursor
							.getColumnIndex(FavouitreItem.Longitude)));	 
				} while (cursor.moveToNext());
		}
		
		return badwheaterarrayList;
	}
	public ArrayList<String> getLatitude() {
		// Fetching the sqLiteDatabase in the readable mode

		ArrayList<String> badwheaterarrayList = new ArrayList<String>();
		if (databaseHelper != null) {

			SQLiteDatabase sqLiteDatabase = databaseHelper
					.getReadableDatabase();
			String[] column = { FavouitreItem.Latitude};
			Cursor cursor = sqLiteDatabase.query(FavouitreItem.TABLE_NAME, column,null,null,null,null,null);
			
			if (cursor.moveToFirst())

				do {
					badwheaterarrayList.add(cursor.getString(cursor
							.getColumnIndex(FavouitreItem.Latitude)));	 
				} while (cursor.moveToNext());
		}
		
		return badwheaterarrayList;
	}
	public ArrayList<String> getProductID() {
		// Fetching the sqLiteDatabase in the readable mode

		ArrayList<String> badwheaterarrayList = new ArrayList<String>();
		if (databaseHelper != null) {

			SQLiteDatabase sqLiteDatabase = databaseHelper
					.getReadableDatabase();
			String[] column = { FavouitreItem.ProductID};
			Cursor cursor = sqLiteDatabase.query(FavouitreItem.TABLE_NAME, column,null,null,null,null,null);
			
			if (cursor.moveToFirst())

				do {
					badwheaterarrayList.add(cursor.getString(cursor
							.getColumnIndex(FavouitreItem.ProductID)));	 
				} while (cursor.moveToNext());
		}
		return badwheaterarrayList;
	}
	public ArrayList<String> getBadWeatherMessage() {
		// Fetching the sqLiteDatabase in the readable mode

		ArrayList<String> badwheaterarrayList = new ArrayList<String>();
		if (databaseHelper != null) {

			SQLiteDatabase sqLiteDatabase = databaseHelper
					.getReadableDatabase();
			String[] column = { FavouitreItem.BadWeatherMessage};
			Cursor cursor = sqLiteDatabase.query(FavouitreItem.TABLE_NAME, column,null,null,null,null,null);
			
			if (cursor.moveToFirst())

				do {
					badwheaterarrayList.add(cursor.getString(cursor
							.getColumnIndex(FavouitreItem.BadWeatherMessage)));	 
				} while (cursor.moveToNext());
		}
		
		return badwheaterarrayList;
	}

	public void getAllData(String selectionArgs) {
		// Fetching the sqLiteDatabase in the readable mode

		if (databaseHelper == null)
		{

		SQLiteDatabase sqLiteDatabase = databaseHelper.getReadableDatabase();
		

		}

	}
	
	
	
	public void getSpecificData(String selectionArgs) {
		// Fetching the sqLiteDatabase in the readable mode

		if (databaseHelper == null)
			return;

		SQLiteDatabase sqLiteDatabase = databaseHelper.getReadableDatabase();

	}

	public void updateAllData(ContentValues contentValues) {
		// Fetching the sqLiteDatabase in the writeable mode

		if (databaseHelper == null)
			return;

		SQLiteDatabase sqLiteDatabase = databaseHelper.getWritableDatabase();

	}

	public void updateSpecificData(String selectionArgs) {
		// Fetching the sqLiteDatabase in the writeable mode

		if (databaseHelper == null)
			return;

		SQLiteDatabase sqLiteDatabase = databaseHelper.getWritableDatabase();

	}

	public void deleteAllData(String productId) {
		// Fetching the sqLiteDatabase in the writeable mode

		if (databaseHelper != null)

		{
		SQLiteDatabase sqLiteDatabase = databaseHelper.getWritableDatabase();
		

	
		

		sqLiteDatabase.delete(FavouitreItem.TABLE_NAME, FavouitreItem.ProductID + "="
				+ productId, null);
		
		
		
		}

	}

	public void deleteSpecificData(String selectionArgs) {
		// Fetching the sqLiteDatabase in the writeable mode

		if (databaseHelper == null)
			return;

		SQLiteDatabase sqLiteDatabase = databaseHelper.getWritableDatabase();

	}
}
